import type { StatisticalIndicator } from '@/types/modules/statistical-indicator'
import { useStatisticalIndicators } from '@/mixins/StatisticalIndicators/MixinStatisticalIndicators'
import { CONTAIN_SUB } from '@/enum/modules/public'

export type IndicatorsByPoint = Partial<StatisticalIndicator>

export function useIndicatorsByPoint() {
  const [lists, setLists] = useShallowState<IndicatorsByPoint[]>([])
  const {
    lists: indicatorLists,
    queryIndicatorsByPage,
  } = useStatisticalIndicators()

  async function getIndicatorsByPointId(id: number) {
    try {
      await queryIndicatorsByPage({
        pageNumber: 1,
        pageSize: 500,
        pointId: id,
        containSub: CONTAIN_SUB.NO_SUB,
      })

      setLists(unref(indicatorLists) as IndicatorsByPoint[])
    }
    catch (e) {
      console.warn(e)
    }
  }

  return {
    lists,
    setLists,
    /** 获取点位下的指标 */
    getIndicatorsByPointId,
  }
}
